//
//  MainTVC.swift
//  微博
//
//  Created by King on 15/9/6.
//  Copyright © 2015年 King. All rights reserved.
//

import UIKit

class MainTVC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

    addChildViewControllers()
    }
    
    /**
    添加4个子控制器
    */
    func addChildViewControllers() {
        addChildViewController(HomeTVC(), title: "首页", image: "tabbar_home")
        addChildViewController(messageTVC(), title: "消息", image:
                                                            "tabbar_message_center")
        addChildViewController(UIViewController())
        addChildViewController(DiscoveryTVC(), title: "发现", image: "tabbar_discover")
        addChildViewController(ProfileTVC(), title: "我", image: "tabbar_profile")
        
    }
    
    func addChildViewController(vc: UIViewController, title: String, image: String) {
        tabBar.tintColor = UIColor.orangeColor()
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: image)
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
        
        
    }
    
    lazy var  composeButton:UIButton =  {
        let button = UIButton()
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Normal)
        button.addTarget(self, action: "click", forControlEvents: UIControlEvents.TouchUpInside)
        self.tabBar.addSubview(button)
        return button
        
    }()
    
    func setComposeButton() {
        let w = tabBar.frame.width / CGFloat((viewControllers?.count)!)
        let rect = CGRect(x: 0, y: 0, width: w, height: tabBar.frame.height)
        composeButton.frame = CGRectOffset(rect, 2 * w, 0)

    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        setComposeButton()
    }
    func click(){

    }
    
}
